//
//  CostReportController.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/7/20.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "CostReportController.h"
#import <BRPickerView/BRPickerView.h>
#import "BillCountModeCell.h"
#import "CostReportContentCell.h"
#import "TemplateFourteenTableViewCell.h"


@interface CostReportController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) CedarButton *comfirmBtn;

@end

@implementation CostReportController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"费用上报";
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.view);
    }];
    
}

#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10.00f;
}



//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = kAppBackgoundColor;
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BillCountModeCell *firstCell = [tableView dequeueReusableCellWithIdentifier:@"BillCountModeCellIdentifier"];
    TemplateFourteenTableViewCell *secondCell = [tableView dequeueReusableCellWithIdentifier:@"TemplateFourteenTableViewCellIdentifier"];
    
    CostReportContentCell *thirdCell = [tableView dequeueReusableCellWithIdentifier:@"CostReportContentCellIdentifier"];

    if (indexPath.section == 0) {

        if (indexPath.row == 0) {
            [secondCell updateTitle:@"订单编号"];
            
        }else if (indexPath.row == 1){
            [secondCell updateTitle:@"公司名"];

        }else if (indexPath.row == 2){
            [secondCell updateTitle:@"订车费用"];

        }else if (indexPath.row == 3){
            [secondCell updateTitle:@"开始时间"];

        }else if (indexPath.row == 4){
            [secondCell updateTitle:@"结束时间"];

        }else {
            [secondCell updateTitle:@"用车数量"];

        }
        return secondCell;
        
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            [secondCell updateTitle:@"上报时段"];
            return secondCell;
        }else {
            return firstCell;
        }
    }else {
            return thirdCell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     if (indexPath.section == 2) {
         return 350 + 65;
     }else {
         return 50;
     }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return   3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 6;
    }else  if (section == 1){
        return 2;
    }else {
        return 1;
    }
    return 0;
}


- (CedarButton *)comfirmBtn{
    if (!_comfirmBtn){
        _comfirmBtn =  [CedarButton buttonWithTextForGradientForCommomn:@"费用上报" radius:YES];
        @weakify(self)
        _comfirmBtn.clickEvent = ^{
            @strongify(self)
        };
    }
    return _comfirmBtn;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UIConfigure tableViewFromFactory];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        [self setUpFooterView];
        [_tableView registerClass:[BillCountModeCell class] forCellReuseIdentifier:@"BillCountModeCellIdentifier"];
        [_tableView registerClass:[TemplateFourteenTableViewCell class] forCellReuseIdentifier:@"TemplateFourteenTableViewCellIdentifier"];
        [_tableView registerClass:[CostReportContentCell class] forCellReuseIdentifier:@"CostReportContentCellIdentifier"];
        
    }
    return _tableView;
}

- (void)setUpFooterView{
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)];
   [footerView addSubview:self.comfirmBtn];
   [self.comfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       make.bottom.mas_equalTo(footerView.mas_bottom).mas_offset(-40);
       make.left.mas_equalTo(footerView).mas_offset(kMarginOffsetX);
       make.right.mas_equalTo(footerView).mas_offset(-kMarginOffsetX);
       make.height.mas_offset(40);
   }];
   footerView.backgroundColor = kAppBackgoundColor;
   _tableView.tableFooterView = footerView;
}



@end
